//
//  TravelsViewController.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2018/1/10.
//  Copyright © 2018年 Lwx. All rights reserved.
//

#define likeableBtnW 30
#define likeNumBtnW 60
#define border 10
#define labelH 20
#define sectionH 80
#import "TravelsViewController.h"
#import "VsitorCommentCell.h"
#import "TravelsModel.h"
#import "VisitorCommentModel.h"
#import "ImmediateEvaluationViewController.h"
#import "TravelNoteCommentViewController.h"
#import "MoreCommentViewController.h"
#import "TravelNoteMoreCommentViewController.h"

@interface TravelsViewController ()<UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, strong)UITableView * tableView;
@property(nonatomic, strong)UIImageView * headImage;
@property(nonatomic, strong)UIView * headerView;
@property(nonatomic, strong)UIButton * likeableBtn;
@property(nonatomic, strong)UIButton * likeNumBtn;
@property(nonatomic, strong)UILabel * titleLab;
@property(nonatomic, strong)UILabel * dateLab;
@property(nonatomic, strong)UIImageView * iconImage;
@property(nonatomic, strong)UILabel * nameLab;
@property(nonatomic, strong)UIButton * loctionBtn;
@property(nonatomic, strong)UILabel * loctionLab;
@property(nonatomic, strong)UILabel * detailLab;
@property(nonatomic, strong)UIImageView * contentImageOne;
@property(nonatomic, strong)UIImageView * contentImageTwo;
@property(nonatomic, strong)UIImageView * contentImageThree;

@property(nonatomic, strong)UIButton * wantCommentBtn;
@property(nonatomic, strong)UIView * footerView;
@property(nonatomic, strong)TravelsModel * travelModel;
@property(nonatomic, strong)VisitorCommentModel * model;
@property(nonatomic, strong)UIView * contentImageBG;
@property (nonatomic, assign)int comments;//还剩多少条评论
@property (nonatomic, strong)UIButton * moreCommentBtn;
@end
@implementation TravelsViewController(Networking)
- (void)getCommentData{
    NSDictionary * dic = @{
                           @"did":@(self.dID),
                           @"type":@(1),
                           };
    WS(ws)
    [self showprogressHUD];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/diary/diaryComment") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        if (error) {
            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){
                ws.model = [VisitorCommentModel yy_modelWithDictionary:obj];
                self.tableView.tableFooterView = self.footerView;
                [self.tableView reloadData];
            }else{
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}

- (void)getTravelsData{
    NSDictionary * dic = @{
                           @"did":@(self.dID),
                           @"mid":[UserModel intance].member_id,
                           };
    WS(ws)
    [self showprogressHUD];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/diary/diaryDetail") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        if (error) {
            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){
                ws.travelModel = [TravelsModel yy_modelWithDictionary:obj[@"data"]];
                [self.tableView reloadData];
            }else{
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}

- (void)getCellData{
    NSDictionary * dic = @{
                           @"did":@(self.dID),
                           @"type":@(1),
                           @"row":@(2)
                           };
    WS(ws)
    [self showprogressHUD];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/diary/diaryComment") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        if (error) {
            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){
                ws.model = [VisitorCommentModel yy_modelWithDictionary:obj];
                
                [self.tableView reloadData];
            }else{
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}

- (void)transformLikesDataWithDid{
    NSDictionary * dic = @{
                           @"mid":[UserModel intance].member_id,
                           @"token":[UserModel intance].token,
                           @"tid":@(self.dID),
                           @"type":@(3)
                           };
    [self showprogressHUD];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/index/collect") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        if (error)
        {
            [[HUDHelper sharedInstance]tipMessage:obj[@"msg"]];
        }
        else
        {
            if ([obj[@"code"] integerValue] == 100000)
            {
                [[HUDHelper sharedInstance]tipMessage:obj[@"msg"]];
            }
            else
            {
                [[HUDHelper sharedInstance]tipMessage:obj[@"msg"]];
            }
        }
    }];
}

@end

@implementation TravelsViewController\
- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"游记详情");
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    self.navigationController.delegate = self;
    
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
//    [self getCommentData];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (self.navigationController.delegate == nil)
    {
        self.navigationController.delegate = self;
    }
    [self getCommentData];
    [self getTravelsData];
    [self getCellData];
}

#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    BOOL isHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isHomePage animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - init
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] init];
        _tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        _tableView.tableHeaderView = self.headerView;
//        _tableView.tableFooterView = self.footerView;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }return _tableView;
}

- (UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc] init];
//        _headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 600);
        UIButton *back = [[UIButton alloc]initWithFrame:CGRectMake(10, 20, 30, 30)];
        [back setImage:[UIImage imageNamed:@"icon_back2lwx"] forState:UIControlStateNormal];
        [back addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
        
        CGFloat dateLabW = 150;
        self.headImage.frame = CGRectMake(0, 0, SCREEN_WIDTH, 200);
        self.likeableBtn.frame = CGRectMake(SCREEN_WIDTH - likeableBtnW - border - 20, 2*border, likeableBtnW, likeableBtnW);
        self.likeNumBtn.frame = CGRectMake(self.likeableBtn.left, self.headImage.bottom - 40, likeNumBtnW, 40);
        self.titleLab.frame = CGRectMake(0, self.headImage.bottom, SCREEN_WIDTH, labelH);
        self.dateLab.frame = CGRectMake(SCREEN_WIDTH - dateLabW, self.titleLab.bottom + border, dateLabW, labelH);
//        self.dateLab.backgroundColor = [UIColor yellowColor];
        self.iconImage.frame = CGRectMake(border, 0, likeableBtnW, likeableBtnW);
        self.iconImage.centerY = self.dateLab.centerY;
        self.nameLab.frame = CGRectMake(self.iconImage.right + border/2, 0, self.dateLab.left - self.iconImage.right - border/2, labelH);
        self.nameLab.centerY = self.dateLab.centerY;
        self.loctionBtn.frame = CGRectMake(self.iconImage.left, self.iconImage.bottom + border, labelH - 5, labelH - 5);
        self.loctionLab.frame = CGRectMake(self.loctionBtn.right, self.loctionBtn.top, SCREEN_WIDTH - border - self.loctionBtn.right, labelH);
        self.loctionLab.centerY = self.loctionBtn.centerY;
        self.detailLab.frame = CGRectMake(self.iconImage.left, self.loctionBtn.bottom + border, SCREEN_WIDTH - 2*border, labelH);
        
        [_headerView addSubview:self.headImage];
        [_headerView addSubview:self.likeableBtn];
        [_headerView addSubview:self.likeNumBtn];
        [_headerView addSubview:back];
        [_headerView addSubview:self.titleLab];
        [_headerView addSubview:self.dateLab];
        [_headerView addSubview:self.iconImage];
        [_headerView addSubview:self.nameLab];
        [_headerView addSubview:self.loctionBtn];
        [_headerView addSubview:self.loctionLab];
        [_headerView addSubview:self.detailLab];
        [_headerView addSubview:self.contentImageBG];
//        [_headerView addSubview:self.contentImageOne];
//        [_headerView addSubview:self.wantCommentBtn];
        _headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.contentImageBG.bottom + border);
        
    }return _headerView;
}

- (UIImageView *)headImage{
    if (!_headImage) {
        _headImage = [[UIImageView alloc] init];
        _headImage.image = [UIImage imageNamed:@"img_list2111"];
    }return _headImage;
}

- (UIButton *)likeableBtn{
    if (!_likeableBtn) {
        _likeableBtn = [[UIButton alloc] init];
        [_likeableBtn setImage:[UIImage imageNamed:@"icon_yj_shoucang1"] forState:UIControlStateNormal];
        [_likeableBtn setImage:[UIImage imageNamed:@"icon_yj_shoucang2"] forState:UIControlStateSelected];
        [_likeableBtn addTarget:self action:@selector(likeableBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }return _likeableBtn;
}

- (UIButton *)likeNumBtn{
    if (!_likeNumBtn) {
        _likeNumBtn = [[UIButton alloc] init];
        [_likeNumBtn setImage:[UIImage imageNamed:@"xcyj_list_shoucang"] forState:UIControlStateNormal];
//        [_likeNumBtn setTitle:@"3321" forState:UIControlStateNormal];
        _likeNumBtn.titleLabel.font = DEF_FontSize_12;
    }return _likeNumBtn;
}

- (UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = DEF_FontSize_14;
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.textColor = [UIColor blackColor];
//        _titleLab.text = @"标题";
    }return _titleLab;
}

- (UILabel *)dateLab{
    if (!_dateLab) {
        _dateLab = [[UILabel alloc] init];
        _dateLab.font = DEF_FontSize_12;
        _dateLab.textAlignment = NSTextAlignmentLeft;
        _dateLab.textColor = [UIColor grayColor];
//        _dateLab.text = @"2018年00月00日 00:00";
    }return _dateLab;
}

- (UIImageView *)iconImage{
    if (!_iconImage) {
        _iconImage = [[UIImageView alloc] init];
        _iconImage.layer.cornerRadius = likeableBtnW/2;
        _iconImage.backgroundColor = [UIColor redColor];
        _iconImage.layer.masksToBounds = YES;
    }return _iconImage;
}

- (UILabel *)nameLab{
    if (!_nameLab) {
        _nameLab = [[UILabel alloc] init];
        _nameLab.font = DEF_FontSize_12;
        _nameLab.textAlignment = NSTextAlignmentLeft;
        _nameLab.textColor = [UIColor blackColor];
//        _nameLab.text = @"未设置";
    }return _nameLab;
}

- (UIButton *)loctionBtn{
    if (!_loctionBtn) {
        _loctionBtn = [[UIButton alloc] init];
        [_loctionBtn setImage:[UIImage imageNamed:@"xc_locationlwx"] forState:UIControlStateNormal];
    }return _loctionBtn;
}

- (UILabel *)loctionLab{
    if (!_loctionLab) {
        _loctionLab = [[UILabel alloc] init];
//        _loctionLab.text = @"具体地点";
        _loctionLab.font = DEF_FontSize_12;
        _loctionLab.textColor = [UIColor blackColor];
    }return _loctionLab;
}

- (UILabel *)detailLab{
    if (!_detailLab) {
        _detailLab = [[UILabel alloc] init];
        _detailLab.font = DEF_FontSize_12;
        _detailLab.textAlignment = NSTextAlignmentLeft;
        _detailLab.textColor = [UIColor blackColor];
        _detailLab.numberOfLines = 0;
        _detailLab.lineBreakMode = NSLineBreakByWordWrapping;
//        _detailLab.text = @"详细信息";
    }return _detailLab;
}

- (UIView *)footerView{
    if (!_footerView) {
        _footerView = [[UIView alloc] init];
        _footerView.backgroundColor = [UIColor whiteColor];
        CGFloat wantCommentW = 80;
        CGFloat btnH = 30;
        self.moreCommentBtn = [[UIButton alloc] init];
        self.moreCommentBtn.backgroundColor = [UIColor whiteColor];
        self.moreCommentBtn.frame = CGRectMake(0, border/2, SCREEN_WIDTH, btnH);
        [self.moreCommentBtn setImage:[UIImage imageNamed:@"icon_in"] forState:UIControlStateNormal];
        [self.moreCommentBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.moreCommentBtn.titleLabel.font = DEF_FontSize_14;
        self.moreCommentBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -160);
        self.moreCommentBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 20);
        [self.moreCommentBtn addTarget:self action:@selector(moreCommentBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [_footerView addSubview:self.moreCommentBtn];
        if (self.comments > 2) {
            self.moreCommentBtn.hidden = NO;
            NSString * num = [NSString stringWithFormat:@"更多%d条评论", self.comments - 2];
            [self.moreCommentBtn setTitle:num forState:UIControlStateNormal];
            NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:num];
            // 需要改变的第一个文字的位置
            NSUInteger firstLoc = [[noteStr string] rangeOfString:@"多"].location + 1;
            // 需要改变的最后一个文字的位置
            NSUInteger secondLoc = [[noteStr string] rangeOfString:@"条"].location;
            // 需要改变的区间
            NSRange range = NSMakeRange(firstLoc, secondLoc - firstLoc);
            [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor cyanColor] range:range];
            [noteStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-BoldOblique" size:18] range:range];
            [self.moreCommentBtn.titleLabel setAttributedText:noteStr];
        }else{
            self.moreCommentBtn.hidden = YES;
        }
        self.wantCommentBtn.frame = CGRectMake((SCREEN_WIDTH - wantCommentW)/2, self.moreCommentBtn.bottom + border, wantCommentW, labelH + border);
        [_footerView addSubview:self.wantCommentBtn];
        
        _footerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.wantCommentBtn.bottom + border);
    }return _footerView;
}

- (UIView *)contentImageBG{
    if (!_contentImageBG) {
        _contentImageBG = [[UIView alloc] init];
        _contentImageBG.backgroundColor = self.headerView.backgroundColor;
        self.contentImageOne.frame = CGRectMake(border, 0, SCREEN_WIDTH - 2*border, self.headImage.height);
        self.contentImageTwo.frame = CGRectMake(self.contentImageOne.left, self.contentImageOne.bottom + 5, SCREEN_WIDTH - 2*border, self.headImage.height);
        self.contentImageThree.frame = CGRectMake(self.contentImageOne.left, self.contentImageTwo.bottom + 5, SCREEN_WIDTH - 2*border, self.headImage.height);
        [_contentImageBG addSubview:self.contentImageOne];
        [_contentImageBG addSubview:self.contentImageTwo];
        [_contentImageBG addSubview:self.contentImageThree];
        _contentImageBG.frame = CGRectMake(0, self.detailLab.bottom + border, SCREEN_WIDTH, self.contentImageThree.bottom);
    }return _contentImageBG;
}

- (UIImageView *)contentImageOne{
    if (!_contentImageOne) {
        _contentImageOne = [[UIImageView alloc] init];
        _contentImageOne.image = [UIImage imageNamed:@"img_list2111"];
    }return _contentImageOne;
}

- (UIImageView *)contentImageTwo{
    if (!_contentImageTwo) {
        _contentImageTwo = [[UIImageView alloc] init];
        _contentImageTwo.image = [UIImage imageNamed:@"img_list2111"];
    }return _contentImageTwo;
}

- (UIImageView *)contentImageThree{
    if (!_contentImageThree) {
        _contentImageThree = [[UIImageView alloc] init];
        _contentImageThree.image = [UIImage imageNamed:@"img_list2111"];
    }return _contentImageThree;
}

- (UIButton *)wantCommentBtn{
    if (!_wantCommentBtn) {
        _wantCommentBtn = [[UIButton alloc] init];
        [_wantCommentBtn setTitle:@"我要评论" forState:UIControlStateNormal];
        [_wantCommentBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [_wantCommentBtn addTarget:self action:@selector(wantCommentBtnClick) forControlEvents:UIControlEventTouchUpInside];
        _wantCommentBtn.titleLabel.font = DEF_FontSize_12;
        [_wantCommentBtn setCornerRadius:8];
        _wantCommentBtn.layer.borderColor = [UIColor orangeColor].CGColor;
        _wantCommentBtn.layer.borderWidth = 1;
    }return _wantCommentBtn;
}

- (void)setTravelModel:(TravelsModel *)travelModel{
    _travelModel = travelModel;
    if ([travelModel.is_collect isEqualToString:@"未收藏"]) {
        self.likeableBtn.selected = NO;
    }
    if ([travelModel.is_collect isEqualToString:@"已收藏"]) {
        self.likeableBtn.selected = YES;
    }
    [self.likeNumBtn setTitle:self.travelModel.likes forState:UIControlStateNormal];
    self.titleLab.text = self.travelModel.title;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:self.travelModel.pic1]];
    self.nameLab.text = self.travelModel.nickname;
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:self.travelModel.avatar]];
    self.dateLab.text = self.travelModel.addtime;
    self.loctionLab.text = self.travelModel.location;
    self.detailLab.text = self.travelModel.content;
    [self.contentImageOne sd_setImageWithURL:[NSURL URLWithString:self.travelModel.pic1]];
    [self.contentImageTwo sd_setImageWithURL:[NSURL URLWithString:self.travelModel.pic2]];
    [self.contentImageThree sd_setImageWithURL:[NSURL URLWithString:self.travelModel.pic3]];
    self.detailLab.height = [self getLabelHeightWithText:self.detailLab.text width:SCREEN_WIDTH font:12];
    self.detailLab.frame = CGRectMake(self.iconImage.left, self.loctionBtn.bottom + border, SCREEN_WIDTH - 2*border, self.detailLab.height);
    if ([self.travelModel.pic3 isEqualToString:@""] || self.travelModel.pic3 == nil) {
        self.detailLab.frame = CGRectMake(self.iconImage.left, self.loctionBtn.bottom + border, SCREEN_WIDTH - 2*border, self.detailLab.height);
        self.contentImageThree.frame = CGRectMake(self.contentImageOne.left, self.contentImageTwo.bottom + 5, SCREEN_WIDTH - 2*border, 0);
        self.contentImageBG.frame = CGRectMake(0, self.detailLab.bottom + border, SCREEN_WIDTH, self.contentImageTwo.bottom);
        self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.contentImageBG.bottom + border);
    }
    if ([self.travelModel.pic2 isEqualToString:@""] || self.travelModel.pic2 == nil) {
        self.detailLab.frame = CGRectMake(self.iconImage.left, self.loctionBtn.bottom + border, SCREEN_WIDTH - 2*border, self.detailLab.height);
        self.contentImageTwo.frame = CGRectMake(self.contentImageOne.left, self.contentImageOne.bottom + 5, SCREEN_WIDTH - 2*border, 0);
        self.contentImageBG.frame = CGRectMake(0, self.detailLab.bottom + border, SCREEN_WIDTH, self.contentImageOne.bottom);
        self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.contentImageBG.bottom + border);
    }
//    self.comments = self.model
}

- (void)setModel:(VisitorCommentModel *)model{
    _model = model;
    self.comments = (int)model.data.count;
}

#pragma mark - action
- (void)backClick:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)likeableBtnClick:(UIButton *)sender{
    sender.selected = !sender.selected;
    [self transformLikesDataWithDid];
}

- (void)wantCommentBtnClick{
    NSLog(@"我要评论");
    TravelNoteCommentViewController * travelNoteComment = [[TravelNoteCommentViewController alloc] init];
    travelNoteComment.navigationItem.title = @"我要评论";
    travelNoteComment.did = self.dID;
    [self.navigationController pushViewController:travelNoteComment animated:YES];
}

- (void)moreCommentBtnClick{
    NSLog(@"查看更多");
    TravelNoteMoreCommentViewController * moreCommentVC = [[TravelNoteMoreCommentViewController alloc] init];
    moreCommentVC.did = self.dID;
    [self.navigationController pushViewController:moreCommentVC animated:YES];
}

#pragma mark - tableViewDelegate和DataSource
//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
//    if (self.model.data.count == 0) {
//        return nil;
//    }
//    UIView * sectionBGView = [[UIView alloc] init];
//    UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1)];
//    lineView.backgroundColor = getColor(bgColor);
//    [sectionBGView addSubview:lineView];
//    UILabel * personalOrderLab = [[UILabel alloc] init];
//    personalOrderLab.font = DEF_FontSize_14;
//    personalOrderLab.textAlignment = NSTextAlignmentCenter;
//    personalOrderLab.frame = CGRectMake(0, 0, SCREEN_WIDTH, 20);
//    [sectionBGView addSubview:personalOrderLab];
//    sectionBGView.frame = personalOrderLab.frame;
//    personalOrderLab.text = @"游客评价";
//
//    return sectionBGView;
//}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.model.data.count >= 2) {
        return 2;
    }else{
        return self.model.data.count;
    }
//    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * cellID = @"cell";
    [self.tableView registerClass:[VsitorCommentCell class] forCellReuseIdentifier:cellID];
    VsitorCommentCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[VsitorCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.modelData = self.model.data[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (self.model.data.count == 0) {
        return 1;
    }else return 20;
}

//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
//    return 20;
//}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (self.model.data.count == 0) {
        return nil;
    }
    UIView * sectionBGView = [[UIView alloc] init];
    UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1)];
    lineView.backgroundColor = getColor(bgColor);
    [sectionBGView addSubview:lineView];
    UILabel * personalOrderLab = [[UILabel alloc] init];
    personalOrderLab.font = DEF_FontSize_14;
    personalOrderLab.textAlignment = NSTextAlignmentCenter;
    personalOrderLab.frame = CGRectMake(0, 0, SCREEN_WIDTH, 20);
    [sectionBGView addSubview:personalOrderLab];
    sectionBGView.frame = personalOrderLab.frame;
    personalOrderLab.text = @"游客评价";
    return sectionBGView;
}

//自适应Lable高度
- (CGFloat)getLabelHeightWithText:(NSString *)text width:(CGFloat)width font: (CGFloat)font
{
    CGRect rect = [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil];
    
    return rect.size.height;
}

@end
